<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        body{
            margin-bottom: 800px;
        }
    </style>
    <script src="./js/vue.js"></script>
</head>
<body>
    <div id="app">
        <pre style="font-size: 20px;">{{arr}}</pre>
        <hr>
        <ul>
            <li v-for="(e, index) in arr" :key="index">
                <span>{{ e }}</span>
                <input type="text" v-model="arr[index]">
                <!-- arr 循环后的构建临时变量 e 为基本变量，和原变量没有任何对应关系 -->
                <!-- <input type="text" v-model="e"> -->
                <!-- 通过下标的数据操作，会导致响应式丢失=>Object.defineProperty的语法问题导致的 -->
                <input type="button" value="重置数据" @click=" arr[index]='重置新数据' ">
            </li>
        </ul>
        <hr>
        <pre style="font-size: 20px;">{{arrs}}</pre>
        <hr>
        <ul>
            <li v-for="(obj, index) in arrs" :key="index">
                <input type="checkbox" :value="obj.email" v-model="selEmail">
                <input type="checkbox" v-model="obj.state">
                <span>{{ obj.email }}</span>
                <input type="text" v-model="arrs[index].email">
                <!-- 
                    arrs 循环后的构建临时变量 obj 为引用类型，和原变量指向同一个地址
                    所以可以直接绑定操作
                -->
                <input type="text" v-model="obj.email">
                <input type="button" value="重置数据" @click=" obj.email='重置数据' ">
            </li>
        </ul>
        <p>被选中了{{ getNums() }}个</p>
        <input type="button" value="选中的email" @click="printEmail()">
    </div>
</body>
<script>
    
    new Vue({
        el:"#app",
        data:{
            arr:[
                "aaaaa@163.com",
                "bbbbb@163.com",
                "ccccc@163.com",
                "ddddd@163.com",
                "eeeee@163.com"
            ],
            arrs:[
                {email:"aaaaa@163.com",state:false},
                {email:"bbbbb@163.com",state:false},
                {email:"ccccc@163.com",state:false},
                {email:"ddddd@163.com",state:false},
                {email:"eeeee@163.com",state:false}
            ],
            selEmail:[]
        },
        methods: {
            getNums(){
                let count = 0;
                this.arrs.forEach(obj => {
                    if(obj.state){
                        count++;
                    }
                });
                return count;
            },
            printEmail(){
                console.log(this.selEmail);
                console.log("-----------------");
                this.arrs.forEach(obj => {
                    if(obj.state){
                        console.log(obj);
                    }
                });
            }
        },
    })
</script>
</html>